import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import Getnew from './Getnew/Getnew'
import Goodslist from './Goodslist/Goodslist'
import { actions, getNewshop,getGoodslist,changeIndex} from '../../store/modules/Home'


export  class Home extends Component {
  componentDidMount(){
    let{
    home:{
      reqgetnew,
    reqgetindexgoods 
    }
    } = this.props;
    reqgetnew();
    reqgetindexgoods();
  }



  render() {
    let { newshop,goodslist,home:{ changeindex },changeIndex } = this.props;
    return (
      <div>
          <Getnew newshop={newshop}></Getnew>
          <Goodslist goodslist={goodslist} changeindex={(n)=>changeindex(n)} n={changeIndex}></Goodslist>
      </div>
    )
  }
}

const mapStateToProps = (state) => ({
  newshop:getNewshop(state),
  goodslist:getGoodslist(state),
  changeIndex:changeIndex(state),
  
});

const mapDispatchToProps = (dispatch) => {
  return {
    home: bindActionCreators(actions, dispatch),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(Home);
